from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-05-01 14:07:42.918761
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 01, May, 2021
Time: 14:07:47
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.9105
Nobs: 278.000 HQIC: -48.6137
Log likelihood: 3362.61 FPE: 4.81766e-22
AIC: -49.0849 Det(Omega_mle): 3.50516e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.421670 0.119970 3.515 0.000
L1.Burgenland 0.072927 0.059762 1.220 0.222
L1.Kärnten -0.224490 0.053026 -4.234 0.000
L1.Niederösterreich 0.091409 0.128610 0.711 0.477
L1.Oberösterreich 0.226481 0.123947 1.827 0.068
L1.Salzburg 0.270353 0.068417 3.952 0.000
L1.Steiermark 0.109221 0.086942 1.256 0.209
L1.Tirol 0.122255 0.060323 2.027 0.043
L1.Vorarlberg -0.036101 0.055316 -0.653 0.514
L1.Wien -0.044613 0.111561 -0.400 0.689
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.441765 0.138871 3.181 0.001
L1.Burgenland 0.005060 0.069178 0.073 0.942
L1.Kärnten 0.329636 0.061380 5.370 0.000
L1.Niederösterreich 0.108420 0.148872 0.728 0.466
L1.Oberösterreich -0.066370 0.143474 -0.463 0.644
L1.Salzburg 0.221454 0.079196 2.796 0.005
L1.Steiermark 0.092233 0.100639 0.916 0.359
L1.Tirol 0.136833 0.069827 1.960 0.050
L1.Vorarlberg 0.151348 0.064031 2.364 0.018
L1.Wien -0.410750 0.129137 -3.181 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.271669 0.060792 4.469 0.000
L1.Burgenland 0.102202 0.030283 3.375 0.001
L1.Kärnten -0.014149 0.026870 -0.527 0.598
L1.Niederösterreich 0.083072 0.065170 1.275 0.202
L1.Oberösterreich 0.285122 0.062807 4.540 0.000
L1.Salzburg 0.017809 0.034669 0.514 0.607
L1.Steiermark -0.000575 0.044056 -0.013 0.990
L1.Tirol 0.069772 0.030567 2.283 0.022
L1.Vorarlberg 0.074767 0.028030 2.667 0.008
L1.Wien 0.112901 0.056531 1.997 0.046
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.211726 0.058307 3.631 0.000
L1.Burgenland 0.028128 0.029045 0.968 0.333
L1.Kärnten 0.008785 0.025771 0.341 0.733
L1.Niederösterreich 0.054087 0.062506 0.865 0.387
L1.Oberösterreich 0.394957 0.060240 6.556 0.000
L1.Salzburg 0.081008 0.033251 2.436 0.015
L1.Steiermark 0.132505 0.042255 3.136 0.002
L1.Tirol 0.050553 0.029318 1.724 0.085
L1.Vorarlberg 0.081292 0.026884 3.024 0.002
L1.Wien -0.043593 0.054220 -0.804 0.421
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.479626 0.113987 4.208 0.000
L1.Burgenland 0.099765 0.056782 1.757 0.079
L1.Kärnten 0.008686 0.050382 0.172 0.863
L1.Niederösterreich 0.006743 0.122196 0.055 0.956
L1.Oberösterreich 0.122185 0.117765 1.038 0.299
L1.Salzburg 0.053368 0.065005 0.821 0.412
L1.Steiermark 0.068751 0.082606 0.832 0.405
L1.Tirol 0.204979 0.057315 3.576 0.000
L1.Vorarlberg 0.033951 0.052557 0.646 0.518
L1.Wien -0.071248 0.105997 -0.672 0.501
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.214532 0.090096 2.381 0.017
L1.Burgenland -0.012099 0.044881 -0.270 0.787
L1.Kärnten -0.006900 0.039822 -0.173 0.862
L1.Niederösterreich -0.016559 0.096584 -0.171 0.864
L1.Oberösterreich 0.415793 0.093082 4.467 0.000
L1.Salzburg 0.013827 0.051380 0.269 0.788
L1.Steiermark -0.027096 0.065292 -0.415 0.678
L1.Tirol 0.162235 0.045302 3.581 0.000
L1.Vorarlberg 0.057114 0.041541 1.375 0.169
L1.Wien 0.205061 0.083781 2.448 0.014
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.218268 0.109257 1.998 0.046
L1.Burgenland 0.021184 0.054426 0.389 0.697
L1.Kärnten -0.070986 0.048291 -1.470 0.142
L1.Niederösterreich -0.060743 0.117126 -0.519 0.604
L1.Oberösterreich 0.019988 0.112879 0.177 0.859
L1.Salzburg 0.082146 0.062307 1.318 0.187
L1.Steiermark 0.323983 0.079178 4.092 0.000
L1.Tirol 0.460940 0.054937 8.390 0.000
L1.Vorarlberg 0.145563 0.050376 2.890 0.004
L1.Wien -0.137375 0.101599 -1.352 0.176
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.211461 0.130599 1.619 0.105
L1.Burgenland 0.042019 0.065057 0.646 0.518
L1.Kärnten -0.075319 0.057724 -1.305 0.192
L1.Niederösterreich 0.108857 0.140005 0.778 0.437
L1.Oberösterreich 0.014369 0.134928 0.106 0.915
L1.Salzburg 0.193142 0.074478 2.593 0.010
L1.Steiermark 0.131433 0.094645 1.389 0.165
L1.Tirol 0.055840 0.065668 0.850 0.395
L1.Vorarlberg 0.106436 0.060217 1.768 0.077
L1.Wien 0.220077 0.121445 1.812 0.070
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.535041 0.072071 7.424 0.000
L1.Burgenland -0.014528 0.035902 -0.405 0.686
L1.Kärnten -0.016099 0.031855 -0.505 0.613
L1.Niederösterreich 0.095204 0.077261 1.232 0.218
L1.Oberösterreich 0.307993 0.074460 4.136 0.000
L1.Salzburg 0.013977 0.041101 0.340 0.734
L1.Steiermark -0.043636 0.052230 -0.835 0.403
L1.Tirol 0.081174 0.036239 2.240 0.025
L1.Vorarlberg 0.101917 0.033230 3.067 0.002
L1.Wien -0.057056 0.067019 -0.851 0.395
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.159716 0.091433 0.167063 0.216899 0.078550 0.084881 0.001447 0.159037
Kärnten 0.159716 1.000000 0.053698 0.212386 0.185680 -0.066104 0.176181 0.020529 0.304413
Niederösterreich 0.091433 0.053698 1.000000 0.244881 0.086212 0.319857 0.146550 0.021031 0.313703
Oberösterreich 0.167063 0.212386 0.244881 1.000000 0.302419 0.258701 0.102251 0.059629 0.141005
Salzburg 0.216899 0.185680 0.086212 0.302419 1.000000 0.148878 0.063572 0.089223 0.017540
Steiermark 0.078550 -0.066104 0.319857 0.258701 0.148878 1.000000 0.096041 0.100033 -0.100702
Tirol 0.084881 0.176181 0.146550 0.102251 0.063572 0.096041 1.000000 0.152447 0.154370
Vorarlberg 0.001447 0.020529 0.021031 0.059629 0.089223 0.100033 0.152447 1.000000 -0.009045
Wien 0.159037 0.304413 0.313703 0.141005 0.017540 -0.100702 0.154370 -0.009045 1.000000